<?php

class PostServicio extends CI_Controller {

    function PostServicio() {
        parent::__construct();
        //Cargar los modelos para la base de datos
        //$this->load->model('Noticias_model');
		$this->load->model('ws/alerta_model');
		$this->load->model('ws/usuario_model');
		$this->load->model('ws/postservicio_model');
		$this->load->library('gcm');
        session_start();
        if (!$this->session->userdata('logged_in')) {
            $this->session->set_flashdata('error', 'Debe haberse logueado');
            redirect('login', 'refresh');
        }
    }
	
    public function index() {
        //cargar las alertas
		$servicios = $this->postservicio_model->get_active_services();	
		
		$this->load->library('googlemaps');
		//$config['center'] = 'auto';
		$config['center'] = '-12.0725,-77.0795';
		$config['zoom'] = '14';
		//$config['cluster'] = TRUE;
		$this->googlemaps->initialize($config);
		
		foreach ($servicios as $alert){
			$marker = array();
			$marker['position'] = "".$alert['posicionY'].",".$alert['posicionX']."";
			$marker['infowindow_content'] = $alert['nombreTipoAlerta'];
			$marker['draggable'] = FALSE;
			$marker['ondblclick'] = "go_service(".$alert['idPostServicio'].")";
			$marker['animation'] = 'DROP';
			$this->googlemaps->add_marker($marker);
		}
		
		$data['map'] = $this->googlemaps->create_map();	
		
        $data['title'] = "CityGuardian - Post-Servicio";
        $data['username'] = $this->session->userdata('username');
        $data['name'] = $this->session->userdata('name');
        $data['acceso'] = $this->session->userdata('acceso');
        $data['main'] = "pages/dashboard_map.php"; //Ruta del contenido del home
		//$data['main'] = "pages/dashboard_content.php";
        $this->load->vars($data);
		$this->load->view('user_views/dashboard_user_view');
        //$this->load->view('user_views/dashboard_user_view');
        //echo "<script languaje='javascript'>alert('Index')</script>";
    }
	
	 public function resueltas() {
        //cargar las alertas
		$servicios = $this->postservicio_model->get_close_services();	
		
		$this->load->library('googlemaps');
		//$config['center'] = 'auto';
		$config['center'] = '-12.0725,-77.0795';
		$config['zoom'] = '14';
		$config['cluster'] = TRUE;
		$this->googlemaps->initialize($config);
		
		foreach ($servicios as $alert){
			$marker = array();
			$marker['position'] = "".$alert['posicionY'].",".$alert['posicionX']."";
			$marker['infowindow_content'] = $alert['nombreTipoAlerta'];
			$marker['draggable'] = FALSE;
			$marker['ondblclick'] = "go_service(".$alert['idPostServicio'].")";
			$marker['animation'] = 'DROP';
			$this->googlemaps->add_marker($marker);
		}
		
		$data['map'] = $this->googlemaps->create_map();	
		
        $data['title'] = "CityGuardian - Post-Servicio - Resueltas";
		$data['isPost'] = "1";
        $data['username'] = $this->session->userdata('username');
        $data['name'] = $this->session->userdata('name');
        $data['acceso'] = $this->session->userdata('acceso');
        $data['main'] = "pages/dashboard_map.php"; //Ruta del contenido del home
		//$data['main'] = "pages/dashboard_content.php";
        $this->load->vars($data);
		$this->load->view('user_views/dashboard_user_view');
        //$this->load->view('user_views/dashboard_user_view');
        //echo "<script languaje='javascript'>alert('Index')</script>";
    }
	
	public function detail($idPostServicio){
		
		$data['map'] = null;
		$data['title'] = "Detalle Post-Servicio";
        $data['username'] = $this->session->userdata('username');
        $data['name'] = $this->session->userdata('name');
        $data['acceso'] = $this->session->userdata('acceso');
        $data['main'] = "pages/dashboard_service.php"; //Ruta del contenido del home	
		$data['postservicio'] = $this->postservicio_model->get_service_by_id($idPostServicio);
		$idAlerta = $data['postservicio']['idAlerta'];
		$data['alerta'] = $this->alerta_model->get_alert_by_id($idAlerta);
		$idUsuario = $data['alerta']['idUsuario'];
		$data['user'] = $this->usuario_model->get_user_by_id($idUsuario);
		if ($data['postservicio']['activo']=='1'){
			$data['servicios'] = $this->postservicio_model->get_all_actions();
		}else{
			$data['servicios'] = $this->postservicio_model->get_actions_by_id($idPostServicio);
		}
        $this->load->vars($data);
		$this->load->view('user_views/dashboard_user_view');
	
	}
	
	public function setAccion($idPostServicio,$accion){
		//$fechIni = $this->input->get('');
		$this->postservicio_model->setAccion($idPostServicio,$accion);
		//redirect('postServicio', 'refresh');
	}
	
    function logout() {
        $this->session->sess_destroy();
        $this->session->unset_userdata('logged_in');
        $this->session->set_flashdata('error', "Usted ha sido deslogueado!");
        redirect('login', 'refresh');
    }
}

?>
